#!/bin/bash

function search_by_snmp()
{
	echo $1 | awk -F '.' '{if (NF > 1) exit 0; exit 1}'
	IS_OID=$?
	if [ $IS_OID -eq 1 ] ; then
		IR_OPT="-IR"
	else
		IR_OPT=""
	fi
	snmptranslate -mAll $IR_OPT -Td $1 2>&1 | awk 'BEGIN\
	{\
		this_oid="";\
	}\
	{\
		if ( $1 ~ /.*-MIB::.*/) \
		{\
			cnt = split( $1, arr, "::");\
			if ( cnt == 2 ) \
			{\
				this_oid=arr[2];\
			}\
		}\
		if ( ( $1 ~ /::=/ ) && ( $2 ~ /{/ ) && ( $NF ~ /}/ ) ) \
		{\
			if ( this_oid == "" ) this_oid = "'"$1"'";\
			for ( i = 3; i < NF; i++ )\
			{\
				cnt = split( $i, arr, "(");\
				if ( cnt != 2 ) \
				{\
					printf(".%s", $i);\
				} else { \
					str = substr( arr[2], 1, length(arr[2]) - 1);\
					printf(".%s", str);\
				}\
			}\
			printf("\n");\
		}\
	}'
	
	return 0
}

while [ $# -gt 0 ] ; do
	search_by_snmp $1
	shift
done

exit 0
